package com.dl.tt.service.impl;

import com.dl.tt.mapper.EmpMapper;
import com.dl.tt.pojo.Dept;
import com.dl.tt.pojo.Emp;
import com.dl.tt.service.EmpService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 47
 * @version 1.0
 */
@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper mapper;
    @Override
    public Emp findEmpByAccountNameAndPassword(String accountName, String password) {
        return this.mapper.queryByAccountNameAndPassword(accountName,password);
    }

    @Override
    public List<Emp> findAllRegister() {
        return this.mapper.queryAllRegister();
    }

    @Override
    public Integer passEmp(int empNo) {
        return this.mapper.updateEmpPass(empNo);
    }

    @Override
    public Integer deleteEmp(int empNo) {
        return this.mapper.updateEmpDelete(empNo);
    }

    @Override
    public List<Dept> findDept() {
        return this.mapper.queryDept();
    }

    @Override
    public Integer addDept(String deptName) {
        return this.mapper.insertDept(deptName);
    }

    @Override
    public Integer addEmp(Emp emp) {
        return this.mapper.insertEmp(emp);
    }

    @Override
    public Integer changePassword(String accountName, String password) {
        return this.mapper.updateAdminPassword(accountName,password);
    }

    @Override
    public PageInfo<Emp> findAllByEmpAndPage(int pageNum, int PageSize, Emp emp) {
        // 1.分页助手开始分页 展现第一页，每页5条数据
        PageHelper.startPage(pageNum,PageSize);
        // 2.调用mapper层select查询方法，紧跟在分页设置后的第一个select查询会被分页查询
        List<Emp> empList = this.mapper.queryByPageAndCondition(emp);
        // 3.封装分页额结果到PageInfo中
        PageInfo<Emp> empPageInfo = new PageInfo<>(empList);
        return empPageInfo;
    }

    @Override
    public Integer changeDeptName(Integer deptNo, String deptName) {
        return this.mapper.updateDeptNameByDeptNo(deptNo,deptName);
    }
}
